package com.kgd.news.ibeetl.func;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.kgd.news.utils.Constants;
import org.beetl.core.Context;
import org.beetl.core.Function;

import java.util.List;

/**
 * @Email: huangsanm@foxmail.com
 * @Date: 2017/7/26
 * @Time: 下午10:45
 * 查询数据库sys_dict表里面的参数
 * 类似于通用工具一样的东西，可以在html里面直接调用
 */
public class DictFunc implements Function {

    @Override
    public Object call(Object[] objects, Context context) {
        //String args = (String) objects[0];
        //String[] objs = args.split(":");
        if(objects.length != 2){
            return "参数错误";
        }
        String group = objects[0] + "";
        Object val = objects[1] + "";
        List<Record> data =  Db.findByCache(Constants.dict_func_cacheName,"dictfunc"+group+val,"select d.name from sys_dict d where d_group = ? and d_value = ?", group, val);
        if(data == null || data.isEmpty()){
            return "无";
        }else{
            return data.get(0).get("name");
        }
    }


}
